name: Publish Docs
on: [workflow_dispatch]
permissions:
    contents: write

env: 
  POETRY_VERSION: "1.3.1"

jobs:
  docs:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Install poetry
        run: pipx install poetry==$POETRY_VERSION
      - name: Set up Python 3.11
        uses: actions/setup-python@v4
        with:
          python-version: "3.11"
          cache: "poetry"
      - name: Install dependencies
        shell: bash
        run: poetry install --with=doc
      - name: sphinx-apidoc
        shell: bash
        run: |
          poetry run poe apidoc
      - name: Sphinx build
        shell: bash
        run: |
          poetry run sphinx-build docs/source _build
      - name: Publish Docs
        uses: peaceiris/actions-gh-pages@v3
        with:
          publish_branch: gh-pages
          github_token: ${{ secrets.GITHUB_TOKEN }}
          publish_dir: _build/
          force_orphan: true
